﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AgencyEntityLib.BaseEntity;
using SqlLibrary;

public partial class Ctl_ctlFilterSave : ImFilter 
{
    public Func<bool> OkOnClick;

    public Func<ListWhere> SaveOnClick;

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    /// <summary>
    /// Приписать к сранице типа 
    /// </summary>
    public string SiteMapItem_Key { get; set; }

    /// <summary>
    /// категорийность внутри страницы
    /// </summary>
    public string InList_Key { get; set; }

    public string btnSave_ClientID { get { return btnHideSave.ClientID.Replace("_", "$"); } }
    public string BtnCancel_ClientID { get { return btnClose.ClientID.Replace("_", "$"); } }


    
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if(SaveOnClick ==null) return ;

        _Where = SaveOnClick();

        if (string.IsNullOrEmpty(txtName.Text))
            return;

        Filter f = new Filter() 
            { 
                SiteMapItem_Key = SiteMapItem_Key, 
                InList_Key = InList_Key, 
                Value = _Where, 
                Name =txtName .Text ,
                Describe =txtDescribe.Text,
                FilterTypeVal =this .FilterType , 
                AddKey =this.AddKey,
                
            };
        

        if (rbFilterType.SelectedValue.ToString() == 0.ToString())
        {   
            GlobalConstants.CurrentAgency.FilterList.Add(f);            
            wsAgency ws = new wsAgency();
            ws.SaveAgency();
        }
        else
        {
            GlobalConstants.CurrentEmployeer.FilterList.Add(f);
            wsFace ws= (wsFace)GlobalConstants.CurrentAgency.WS_FactoryList[WS_FactoryList.wsKey_Face];
            
            ws.SaveFace(GlobalConstants.CurrentEmployeer);
            //GlobalConstants.CurrentEmployeer.Save();
        }

        OkOnClick();
    }

    private ListWhere _Where = null;
    
}
